// import 'package:flutter_alipay/flutter_alipay.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:fluwx/fluwx.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
import 'package:tobias/tobias.dart' as tobias;

class PayUtils {
  //微信支付
  static Future<bool> wxpay(Map<String, dynamic> params) async {
    // = json.decode(jsonStr);

    //
    print('获取微信相关');
    // print(params);
    //    required String appId,
    // required String partnerId,
    // required String prepayId,
    // required String packageValue,
    // required String nonceStr,
    // required int timeStamp,
    // required String sign,
    bool b = await registerWxApi(
        appId: params['appid'].toString(),
        doOnAndroid: false,
        doOnIOS: true,
        // universalLink: 'https://fjbamztest.jiliol.net/yeyue/'
        universalLink: params['link'].toString()
        );

    print(b);

    bool a = await fluwx.payWithWeChat(
        appId: params['appid'].toString(),
        partnerId: params['partnerid'].toString(),
        prepayId: params['prepayid'].toString(),
        packageValue: params['package'].toString(),
        nonceStr: params['noncestr'].toString(),
        timeStamp: int.parse(params['timestamp'].toString()),
        // signType: "md5",
        sign: params['signPay'].toString());
    if (a) {
    } else {
      // EasyLoading.showToast('支付失败');
    }

    return a;
  }

  // 支付宝支付
  static Future<bool> alipay(String data) async {
    // String data = await StudentMineRequest.payAli(params);
    // print('获取支付宝相关');
    // print(data);
    // Map<dynamic, dynamic> result = await tobias.aliPay(data);

    var payResult = await tobias.aliPay(data);
    if (payResult['resultStatus'] == '9000') {
      print('支付成功');
      EasyLoading.showToast('支付成功');
      return true;
    } else if (payResult['resultStatus'] == '8000') {
      return false;
    } else {
      EasyLoading.showToast('支付失败');
      return false;
    }
  }
}
